package com.example.app06_component;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.SeekBar;

public class ProgressbarActivity extends AppCompatActivity {

    private static final String TAG = "ProgressbarActivity";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progressbar);

        Log.i(TAG, "onCreate()");

        LinearLayout llProgressbarLoading = findViewById(R.id.ll_progress_loading);
        ProgressBar pbProgressbarLoading = findViewById(R.id.pb_progressbar_loading);
        SeekBar sbProgressbarLoading = findViewById(R.id.sb_progressbar_loading);

        // 给SeekBar设置滑动监听
        sbProgressbarLoading.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
            @Override
            public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
                // 滑杆移动
                Log.i(TAG, "onProgressChanged: 滑杆移动");
            }

            @Override
            public void onStartTrackingTouch(SeekBar seekBar) {
                // 按下滑杆
                Log.i(TAG, "onStartTrackingTouch: 按下滑杆");
            }

            @Override
            public void onStopTrackingTouch(SeekBar seekBar) {
                // 离开滑杆
                Log.i(TAG, "onStopTrackingTouch: 离开滑杆");

                // 获取 seekbar 的进度
                int progress = seekBar.getProgress();
                // 设置progressbar的进度
                pbProgressbarLoading.setProgress(progress);

                // 判断进度值是否达到最大值
                if (progress == seekBar.getMax()) {
                    // 设置llProgressbarLoading隐藏
                    // 不可见，但是占用空间
                    // llProgressbarLoading.setVisibility(View.INVISIBLE);
                    // 不可见，不占用空间
                    llProgressbarLoading.setVisibility(View.GONE);
                } else {
                    // 设置llProgressbarLoading显示
                    llProgressbarLoading.setVisibility(View.VISIBLE);
                }
            }
        });
    }
}